# 引包
import os
import time
import HTMLTestRunnerPlugins
import unittest

# 确定文件夹路径
base_path = os.path.dirname(__file__)  # 获取当前文件所在目录--项目目录
case_path = os.path.join(base_path, "Case")  # 用例路径
report_path = os.path.join(base_path, "Report")  # 报告路径,在项目中添加Report文件夹中
# 确定测试报告名称  时间命名
now = time.strftime("%Y-%m-%d %H_%M_%S")  # 格式化时间
print(now)
report_name = now + "HTMLReport.html"  # 报告名称
report_file_path = os.path.join(report_path, report_name)  # html报告路径
print(report_file_path)
# 收集测试用例
suite = unittest.defaultTestLoader.discover(case_path)
# 执行测试用例并生成报告
with open(report_file_path, "wb") as fp:
    runner = HTMLTestRunnerPlugins.HTMLTestRunner(stream=fp, title="ECshop页面自动化测试",
                                                  description="功能测试", tester="0605第6组")
    runner.run(suite)
